
import api from '../../utils/api'
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
   
    imageBaseURL: app.imageBaseURL,
    imageResizeParams: app.imageResizeParams,
    list:[],
    pagesize:10,
    id:'',
    img:'',
  },
  goThemeClassDetail(e) {   
    wx.navigateTo({
      url: "/pages/index_theme_class_detail/index?id=" + e.currentTarget.dataset.id
    })
  },
  //列表信息
  async getList (id) {
    let data={}
    data['flag'] = 'theme'
    data['action'] = 'base_list'
    data['location[lng]'] = app.globalData.currpoint.longitude
    data['location[lat]'] = app.globalData.currpoint.latitude
    data['theme_id'] = id
    data['page'] = 1
    data['pageSize'] = this.data.pagesize
    const {recode, result, message} = await api.send(data)
    if(recode === 'SUCC') {
      result.forEach((item,index) => {
        let arr = item.url.split(",");
        let httpArr = [];
        arr.forEach((img,ind) => {
          httpArr.push(this.loadImg(img))
        })
        item.url = httpArr
      })
      console.log(result)
      this.setData({
        list:result,
      })
    }else {
      Toast(message)
    }
  },
  //图片加载
  loadImg(img){
    let url =  api.checkurl(img)
    return url
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title:options.title,
    })
    this.getList(options.id)
    this.setData({
      id:options.id,
      img:options.img
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.data.pagesize += 10;
    this.setData({
      pagesize:this.data.pagesize
    })
    this.getList(this.data.id)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})